#include "databasehelper.h"
#include "loginwindow.h"
#include "mainwindow.h"
#include "ui_loginwindow.h"
#include "Utils/systemutils.h"
#include <QGraphicsDropShadowEffect>
#include <QColor>
#include <QWidget>
#include <QMouseEvent>
#include  <QMessageBox>
LoginWindow::LoginWindow(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::LoginWindow)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::FramelessWindowHint);
    //this->setAttribute(Qt::WA_TranslucentBackground);
    SystemUtils::setDropShadow(this->ui->img_logo,QColor("red"),20);
    SystemUtils::setDropShadow(this->ui->bnlogin,QColor("skyblue"),20);
    behaviorInit();
}

LoginWindow::~LoginWindow()
{
    delete ui;
}

void LoginWindow::on_bnclose_clicked()
{
    this->close();
}

void LoginWindow::on_bnlogin_clicked()
{
    ui->txt_msg->clear();
    if(this->ui->txt_user->text().isEmpty())
    {
        ui->txt_user->setFocus();
        ui->txt_msg->setText("用户名不可为空");
        return;
    }
    if(this->ui->txt_pwd->text().isEmpty())
    {
        ui->txt_pwd->setFocus();
        ui->txt_msg->setText("用户密码不可为空");
        return;
    }
    DatabaseHelper dbhelper;
    if(dbhelper.isExist(ui->txt_user->text(),ui->txt_pwd->text()))
    {
        MainWindow *win = new MainWindow;
        win->show();
    }else
    {
        QMessageBox::critical(this,"operate info","用户名或密码错误，请重新输入...");
    }
      ui->txt_user->clear();
      ui->txt_pwd->clear();
      ui->txt_msg->clear();
      ui->txt_user->setFocus();
    this->close();
}

void LoginWindow::behaviorInit()
{
    //connect(this->ui->logo,&QWidget::mousePressEvent,this,&LoginWindow::mousePressEvent);
}

void LoginWindow::mousePressEvent(QMouseEvent *e)
{

}

void LoginWindow::mouseMoveEvent(QMouseEvent *e)
{

}

void LoginWindow::mouseReleaseEvent(QMouseEvent *event)
{

}
